﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Frogism.Core;
using Frogism.Data;
using NUnit.Framework;
namespace Frogism.Tests {
  [TestFixture]
  public class AccountLoaderTest {
      private IAccountLoader al;
      [SetUp]
      public void SetUp()
      {
          var user = new Data._2.UserRepository().GetOne(1);

          al = new AccountLoader(user);
      }
    [Test]
    public void CreateAccountLoader() {
  
      Assert.IsNotNull(al);
    }
    [Test]
    public void GetAll() {
      
      IEnumerable<IAccount> accounts = al.GetAll();
      Assert.IsNotNull(accounts);
    }
    [Test]
    public void GetAccountById() {
      IAccount a = al.GetById(1);
      Assert.IsNotNull(a);
    }
    [Test]
    public void CheckAccountIdAfterGettingIt() {
      IAccount a = al.GetById(1);
      Assert.AreEqual(1, a.Id);
    }
    [Test]
    public void GetAccountByIdinvalidId() {
      Assert.IsNull(al.GetById(-9999999));
    }
    [Test]
    [ExpectedException("System.Data.SqlClient.SqlException")]
    public void GetAccountByIdErrorHandling() {
      TestLoader tl = new TestLoader();
      tl.TestProcedureGetOne();
    }

    private class TestLoader : LoaderBase<ObjectIdBase,IObjectIdBase> {
     
      public void TestProcedureGetOne() {
        ProcedureGetOne("InvalidName", 0);
      }

      protected override string ProcNameGetAll {
        get { throw new NotImplementedException(); }
      }

      protected override string ProcNameGetById {
        get { throw new NotImplementedException(); }
      }

      protected override IObjectIdBase GetEmptyObject() {
        throw new NotImplementedException();
      }

      protected override void FillObject(IObjectIdBase i, FriendlyReader reader) {
        throw new NotImplementedException();
      }
    }
  }
}
